import axios from "axios";
import cgi from "conf/cgi";
import runtime from "utils/runtime";

//mock数据
import mockData from "./mockData";

export default {
    ["common.navList"](context) {
        return axios.get(cgi.navList)
            .then(res => {
                if (res.code == 0) {
                    context.commit("common.navList", res.data);
                    return res.data;
                } else {
                    return Promise.reject("请求数据失败!");
                }
            }, error => {
                return Promise.reject(error.msg);
            });
    },
    ["common.user"](context) {
        var user = runtime.getUser();
        return new Promise(function (resolve,reject) {
            if(user) {
                context.commit("common.user", user);
                return resolve();
            } else {
                location.href= '/login.html?from='+ encodeURI(location.href);
                return reject();
            }
        })
    },
    ["common.crumbData"](context) {

    },
    ["common.subNavList"](context) {
        return axios.get(cgi.subNavList)
            .then(res => {
                if (res.code == 0) {
                    context.commit("common.subNavList", res.data);
                    return res.data;
                } else {
                    return Promise.reject("请求数据失败!");
                }
            }, error => {
                return Promise.reject(error.msg);
            });
    }
}